package com.example.scope;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.print.attribute.SetOfIntegerSyntax;

@Service
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class SingletonInstance {

    // 延迟注入、代理解决
    // @Lazy
    // @Autowired
    // private PrototypeInstance instance;

    // 工厂注入解决
    // @Autowired
    // private ObjectFactory<PrototypeInstance> objectFactory;

    // 从容器获取
    @Autowired
    private ApplicationContext applicationContext;


    public PrototypeInstance getInstance() {
        System.out.println("call getInstance");
        return applicationContext.getBean(PrototypeInstance.class );
    }
}
